package conversion

import (
	"fmt"
	"gitee.com/filters/utils/config"
	"os"
)

func mainw() {
	// 创建测试配置文件
	testConfig := `
mysql:
  DBPayAmount:
    host: "xxxx"
    port: 3233
    username: "root"
    password: "xxxx"
    database: "xxxx"
    charset: "utf8mb4"

redis:
  RedisWaiFa:
    host: "localhost"
    port: 6379
    password: ""
    db: 0

config:
  XinyueAMSConf:
    app_id: "xinyue_app"
    secret: "xinyue_secret"
    url: "https://xinyue.api.com"
`

	// 写入配置文件
	err := os.WriteFile("debug_config.yaml", []byte(testConfig), 0644)
	if err != nil {
		fmt.Printf("Failed to write config file: %v\n", err)
		return
	}
	defer os.Remove("debug_config.yaml")

	// 使用 config 包读取配置
	reader := config.NewConfigReader("debug_config.yaml")
	configData, err := reader.GetAllConfig()
	if err != nil {
		fmt.Printf("Failed to read config: %v\n", err)
		return
	}

	fmt.Printf("Config data type: %T\n", configData)
	fmt.Printf("Config data: %+v\n", configData)

	// 检查 mysql 配置
	if mysqlConfig, ok := configData["mysql"]; ok {
		fmt.Printf("MySQL config type: %T\n", mysqlConfig)
		fmt.Printf("MySQL config: %+v\n", mysqlConfig)

		if mysqlMap, ok := mysqlConfig.(map[string]interface{}); ok {
			if dbConfig, ok := mysqlMap["DBPayAmount"]; ok {
				fmt.Printf("DBPayAmount config type: %T\n", dbConfig)
				fmt.Printf("DBPayAmount config: %+v\n", dbConfig)
			}
		}
	}

	fmt.Println("Debug completed successfully!")
}
